﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Renci.iRods.Common;

namespace Renci.iRods.Data
{
    public class Server : DataItem
    {
        [iRodsColumn(DataObjectAttributes.COL_SL_HOST_NAME)]
        public string HostName { get; internal set; }

        [iRodsColumn(DataObjectAttributes.COL_SL_RESC_NAME)]
        public string ResourceName { get; internal set; }

        [iRodsColumn(DataObjectAttributes.COL_SL_CPU_USED)]
        public int CpuUsage{ get; internal set; }

        [iRodsColumn(DataObjectAttributes.COL_SL_MEM_USED)]
        public int MemoryUsage { get; internal set; }

        [iRodsColumn(DataObjectAttributes.COL_SL_SWAP_USED)]
        public int SwapUsage { get; internal set; }

        [iRodsColumn(DataObjectAttributes.COL_SL_RUNQ_LOAD)]
        public int RunQLoad { get; internal set; }

        [iRodsColumn(DataObjectAttributes.COL_SL_DISK_SPACE)]
        public int DiskSpace { get; internal set; }

        [iRodsColumn(DataObjectAttributes.COL_SL_NET_INPUT)]
        public int NetInput { get; internal set; }

        [iRodsColumn(DataObjectAttributes.COL_SL_NET_OUTPUT)]
        public int NetOutput { get; internal set; }

        [iRodsColumn(DataObjectAttributes.COL_SL_CREATE_TIME)]
        public DateTime CreatedTime { get; internal set; }

        internal Server(IRodsConnection connection)
            : base(connection)
        {

        }

        public Server(IRodsConnection connection, string hostName, string resourceName)
            : base(connection)
        {
            this.HostName = hostName;
            this.ResourceName = resourceName;
        }

        public override void Refresh()
        {
            this.Exists = this.Load((q) =>
            {
                q.AddCondition(DataObjectAttributes.COL_SL_HOST_NAME, string.Format("='{0}'", this.HostName));
                q.AddCondition(DataObjectAttributes.COL_SL_RESC_NAME, string.Format("='{0}'", this.ResourceName));
            });
        }
    }
}
